package layui.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 定义过滤器 - 实现编码的设置
 *
 * @Author zqx
 * @Date 2023-11-22
 */
@WebFilter("/*")
public class EncodingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest)servletRequest ;
        // HttpServletResponse resp = (HttpServletResponse)servletResponse ;
        req.setCharacterEncoding("UTF-8");
        // resp.setCharacterEncoding("UTF-8");
        // 放行
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
